package tweeter_parser;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class SingleFileParser 
{
	public int myID;
	double from =0;
	double to= 0;
	List<Event> myEvents;
	double date = 0;
	 
	
	public static void main(String[] args) {
		SingleFileParser sfp = new SingleFileParser("C:/Users/gilga/workspace/ConformityParser/event/event/1/1902_event",3,6);
		System.out.println(sfp.myID);
		System.out.println(sfp.myEvents.get(1).Tweet);
	}
	
	SingleFileParser(String filename,double fromDay, double toDay)
	{
		from = 1000*60*60*24*fromDay;
		to 	 = 1000*60*60*24*toDay;
		
		
		
		myEvents = new ArrayList<Event>();
		File f = new File(filename);
		myID = Integer.parseInt(f.getName().split("_")[0]);
		
		try{
			// Open the file that is the first 
			// command line parameter
			FileInputStream fstream = new FileInputStream(filename);
			// Get the object of DataInputStream
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;
			//Read File Line By Line
			while ((strLine = br.readLine()) != null)   {
				// Print the content on the console
				parse(strLine);
			}
			//Close the input stream
			in.close();
		}catch (Exception e){//Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}


	private void parse(String rawLine)
	{
		
		Event e = new Event(rawLine.split(" "));
		//when I upgrade the parser I can check here if the event is in range. 
		
		
		
		date += e.delta;
		
		if(date >from && date<to)
			myEvents.add(e);
		
		
	}
}
